﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.OA.PageBusiness.PageBusinessConfig;
using BlackCoffeeRESTful.Configs;
using BCService.OA.PageBusiness.PageBusinessConfig;
using BCService.Utils;

namespace BlackCoffeeRESTful.Controllers.Management.OA.PageBusiness.PageBusinessConfig
{
    /// <summary>
    /// OA系统页面业务配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class PageBusinessConfigController : ManagementBaseController
    {
        private readonly IPageBusinessConfigService pageBusinessConfigService;

        public PageBusinessConfigController(IPageBusinessConfigService pageBusinessConfigService)
        {
            this.pageBusinessConfigService = pageBusinessConfigService;
        }

        #region 添加OA系统页面业务配置
        /// <summary>
        ///  添加OA系统页面业务配置
        /// </summary>
        /// <param name="requestDto">OA系统页面业务配置信息</param>
        /// <response code="201">添加OA系统页面业务配置成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统页面业务配置")]
        [ProducesResponseType(typeof(PageBusinessConfigDto), 201)]
        public IActionResult Post(
            [FromBody]PageBusinessConfigRequestDto requestDto)
        {
            var result = this.pageBusinessConfigService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/PageBusinessConfig/{0}", result.PageBusinessConfigId), result);
        }
        #endregion

        #region 修改OA系统页面业务配置
        /// <summary>
        ///  修改OA系统页面业务配置
        /// </summary>
        /// <param name="pageBusinessConfigId">OA系统页面业务配置Id</param>
        /// <param name="requestDto">OA系统页面业务配置信息</param>
        /// <response code="200">修改OA系统页面业务配置成功</response>
        /// <returns></returns>
        [HttpPut("{page_business_config_id}")]
        [Log("修改OA系统页面业务配置")]
        [ProducesResponseType(typeof(PageBusinessConfigDto), 200)]
        public IActionResult Post([FromRoute(Name = "page_business_config_id")]long pageBusinessConfigId, [FromBody]PageBusinessConfigRequestDto requestDto)
        {
            PageBusinessConfigPutDto putDto = requestDto.As<PageBusinessConfigPutDto>();
            putDto.PageBusinessConfigId = pageBusinessConfigId;
            return this.Ok(this.pageBusinessConfigService.Update(putDto));
        }
        #endregion

        #region 删除OA系统页面业务配置
        /// <summary>
        ///  删除OA系统页面业务配置
        /// </summary>
        /// <param name="pageBusinessConfigId">OA系统页面业务配置Id</param>
        /// <response code="204">删除OA系统页面业务配置成功</response>
        /// <returns></returns>
        [HttpDelete("{page_business_config_id}")]
        [Log("删除OA系统页面业务配置")]
        public IActionResult Delete([FromRoute(Name = "page_business_config_id")]long pageBusinessConfigId)
        {
            this.pageBusinessConfigService.Delete(pageBusinessConfigId);
            return this.NoContent();
        }
        #endregion

        #region 获取OA系统页面业务配置
        /// <summary>
        ///  获取OA系统页面业务配置
        /// </summary>
        /// <param name="pageBusinessConfigId">OA系统页面业务配置Id</param>
        /// <response code="200">获取OA系统页面业务配置</response>
        /// <returns></returns>
        [HttpGet("{page_business_config_id}")]
        [ProducesResponseType(typeof(PageBusinessConfigDto), 200)]
        public IActionResult Get([FromRoute(Name = "page_business_config_id")]long pageBusinessConfigId)
        {
            return this.Ok(this.pageBusinessConfigService.GetEntity(pageBusinessConfigId));
        }
        #endregion

        #region 获取OA系统页面业务配置列表
        /// <summary>
        ///  获取OA系统页面业务配置列表
        /// </summary>
        /// <response code="200">获取OA系统页面业务配置列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageBusinessConfigDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.pageBusinessConfigService.GetList(this.Admin.CompanyId));
        }
        #endregion

        #region 获取OA系统页面业务配置（分页）
        /// <summary>
        ///  获取OA系统页面业务配置（分页）
        /// </summary>
        /// <param name="pageBusinessName">页面业务名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统页面业务配置（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<PageBusinessConfigDto>), 200)]
        public IActionResult Query([FromQuery(Name = "page_business_name")]string pageBusinessName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.pageBusinessConfigService.Query(this.Admin.CompanyId,pageBusinessName, start,end,pageIndex, pageSize));
        }
        #endregion

    }
}
